var addRepairListData = function (pageSize, pageNumber) {
    isNulltoWhat(pageSize, 8);
    isNulltoWhat(pageNumber, 1);
    var loadDiv = load("#body", 999999);
    $(".list-content").children("table").children("tbody").html("");
    $(".chooseNum").children("select").html("");
    $.ajax({
        url: "repairTask/list",
        type: "post",
        data: {
            "token": localStorage['token'],
            "pageSize": pageSize,
            "pageNumber": pageNumber
        },
        success: function (data) {
            console.log(data);
            if (data.code == 200) {
                console.log(1);
                var length = data.data.content.length;
                listSetting(data.data.totalPages, data.data.pageNumber);
                localStorage['pageSize'] = data.data.pageSize + "";
                localStorage['pageNumber'] = data.data.pageNumber + "";
                for (var j = 0; j < data.data.totalPages; j++) {
                    var option = addRealOption(j + 1);
                    if ((j + 1) == data.data.pageNumber) {
                        option.attr("selected", "selected");
                    }
                    option.appendTo($(".chooseNum").children("select"));
                }
                ;
                for (var i = 0; i < length; i++) {
                    var task = data.data.content[i];
                    var tr = $('<tr></tr>');
                    var state = stateChangeText(task.state);
                    addTd(task.device).appendTo(tr);
                    addTd(task.content).appendTo(tr);
                    addTd(formatTime(task.updateTime)).appendTo(tr);
                    addTd(state).appendTo(tr);
                    $(' <td>\n' + ' <button  onclick="repair_detail($(this))" >查看</button>\n' + ' </td>').appendTo(tr);
                    addTdHidId(task.id).appendTo(tr);
                    addTdHidId(task.state).appendTo(tr);
                    tr.appendTo($(".list-content").children("table").children("tbody"))
                }
                $(".thisNum").children("span").text(data.data.pageNumber);
                // console.log(new Date().getSeconds() );
                if ($(".list-content").children("table").children("tbody").text() === "") {
                    var bk = getNothingBackground();
                    bk.appendTo($(".list-content").children("table").children("tbody"));
                }
            }
            load_close(loadDiv);
        }
    })
};

var stateChangeText = function (code) {
    var msg = "";
    if (code == 0) {
        msg = "审核中";
    } else if (code == 1) {
        msg = "分配任务中";
    } else if (code == 2) {
        msg = "处理中";
    } else if (code == 3) {
        msg = "已处理";
    } else if (code == 4) {
        msg = "未通过审核";
    }
    return msg;
};

var repair_detail = function (btn) {
    var id = btn.parent().next().text();
    var stateCode = btn.parent().next().next().text();
    localStorage['state'] = stateCode;
    console.log(id);
    var url = "/page/student/repairDetail";
    $("#body").load(url);
};


$("#next").click(function () {
    if (!$(this).hasClass("notAllow")) {
        var pageNumber = parseInt($(".thisNum").children("span").text()) + 1;
        // load($(".list"), 1000);
        addRepairListData(localStorage['pageSize'], pageNumber);
    }

});

$("#last").click(function () {
    if (!$(this).hasClass("notAllow")) {
        var pageNumber = parseInt($(".thisNum").children("span").text()) - 1;
        addRepairListData(localStorage['pageSize'], pageNumber);
    }

});


$(".chooseNum").children("select").change(function () {

    addRepairListData(localStorage['pageSize'], $(this).val());
});
